const Controller = require('./base');
/**
 * @controller Sign
 */
 class SignController extends Controller { 

  async list() {  
    const { ctx ,app} = this;   
    let {  uid } = ctx.request.body; 
    const results = await app.mysql.select('sign',{
      where: { uid: id },
      orders: [['created_at','desc'], ['id','desc']],
      limit: 10,
      offset: 0
    });
    console.log("results",results) 
    this.success(results) 
  } 
  
  async sign() {  
    let {  uid } = ctx.request.body; 
    const record = await this.app.mysql.get('sign', {  
      uid:uid, 
      created_time:this.formatDate(Date.now(),"YYYY-MM-DD"),
    });  
    if(record)  return  this.success(record) // this.error('已签到过')  
    let data = await this.app.mysql.insert('sign',{ 
      uid:uid, 
      created_time:this.formatDate(Date.now(),"YYYY-MM-DD"),// "2020-10-10 10:10:10" 
    })
    console.log(id,data)
    this.success(data)

 }
  
}
module.exports =  SignController
/*
CREATE TABLE `sign`  (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `uid` int(11),
  `created_time` datetime(0) DEFAULT NULL,  
  PRIMARY KEY (`id`) USING BTREE
); 
*/